var express = require('express');
var router = express.Router();
const FileData = require("../data/FileData");

/* GET home page. */
// put all the reviews into this index page!!
router.get('/', async function(req, res, next) {
  let reviews = await FileData.readReviewFile("./data/reviews.json");
  res.locals.reviews = reviews;

  // 登录数字验证码
  res.locals.firstnum = req.session.firstnum = Math.round(Math.random() * 10);
  res.locals.secondnum = req.session.secondnum = Math.round(Math.random() * 10);

  // 记录此时的user
  res.locals.user = req.session.user;
  req.session.save(() => {
    res.render('index');
  });
});

module.exports = router;
